import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import Components from 'unplugin-vue-components/vite'
import { AntDesignVueResolver } from 'unplugin-vue-components/resolvers'
// https://vitejs.dev/config/
export default defineConfig({
    plugins: [
        vue(),
        Components({
            resolvers: [
                AntDesignVueResolver({
                    importStyle: false // css in js
                })
            ]
        })
    ],
    resolve: {
        alias: {
            '@': fileURLToPath(new URL('./src', import.meta.url))
        }
    },
    optimizeDeps: {
        include: [
            '@jiaminghi/c-render',
            '@jiaminghi/c-render/lib/plugin/util',
            '@jiaminghi/charts/lib/util/index',
            '@jiaminghi/charts/lib/util',
            '@jiaminghi/charts/lib/extend/index',
            '@jiaminghi/charts',
            '@jiaminghi/color'
        ]
    },
    server: {
        // port: 3001, // 设置服务启动端口号
        // open: true, // 设置服务启动时是否自动打开浏览器
        // cors: true, // 允许跨域
        proxy: {
            '/api': {
                //apiTest是自行设置的请求前缀，按照这个来匹配请求，有这个字段的请求，就会进到代理来
                target: 'http://127.0.0.1:3001',
                changeOrigin: true, //是否跨域
                rewrite: (path) => path.replace('', '')
            }
        }
    }
})
